<?php
class msetsubmenu extends CI_Model{
	var $submenu = "set_submenu";

	function __construct()
	{
		parent::__construct();
	}
	
	function setData($id_submenu,$id_menu,$nama_submenu,$urutan_submenu,$type_submenu,$enable_submenu)
	{
		$this->id_submenu= $id_submenu;
		$this->id_menu= $id_menu;
		$this->nama_submenu= $nama_submenu;
		$this->urutan_submenu= $urutan_submenu;
		$this->type_submenu= $type_submenu;
		$this->enable_submenu= $enable_submenu;
	}
	
	function getList($page,$uri_segment){
		$this->db->join('set_menu', 'set_menu.id_menu = set_submenu.id_menu', 'left');
		$query = $this->db->get($this->submenu, $page, $uri_segment);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getComboList($type_submenu){
		$this->db->where('type_submenu', $type_submenu);
		$this->db->where('enable_submenu', '1');
		$query = $this->db->get($this->submenu);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function create()
	{	
		$arrayData = array(
			'id_submenu'=>$this->id_submenu,
			'id_menu'=>$this->id_menu,
			'nama_submenu'=>$this->nama_submenu,
			'urutan_submenu'=>$this->urutan_submenu,
			'type_submenu'=>$this->type_submenu,
			'enable_submenu'=>$this->enable_submenu
		);
		return $this->db->insert($this->submenu, $arrayData);
	}
	
	function update($id_submenu)
	{
		$arrayData = array(
			'id_menu'=>$this->id_menu,
			'nama_submenu'=>$this->nama_submenu,
			'urutan_submenu'=>$this->urutan_submenu,
			'type_submenu'=>$this->type_submenu,
			'enable_submenu'=>$this->enable_submenu
		);
		$this->db->where('id_submenu', $id_submenu);
		return $this->db->update($this->submenu, $arrayData);
	}
        
	function remove($id_submenu)
	{
		$this->db->where('id_submenu', $id_submenu);
		return $this->db->delete($this->submenu);
	}	
	
	function detail($id_submenu)
	{
		$this->db->where('id_submenu', $id_submenu);
		$query = $this->db->get($this->submenu);	
		return $query->result_array();
	}
	
	function getListSearch($name){
		$this->db->like('nama_submenu',$name);
		$query = $this->db->get($this->submenu);
		if($query->num_rows() > 0){
			foreach($query->result_array() as $row){
				$result[] = $row;
			}
			return $result;
		} else {
			return false;
		}	
	}
	
	function getForWeb($id_submenu){
		$this->db->where('id_submenu', $id_submenu);
		$query = $this->db->get($this->submenu);
		return $query->result_array();
	}
	
	function getForWebByMenu($id_menu){
		$this->db->where('id_menu', $id_menu);
		$this->db->order_by("urutan_submenu", "asc"); 
		$query = $this->db->get($this->submenu);
		return $query->result_array();
	}
}
?>